package com.jh3502.vivo.function.contact;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jh3502.vivo.R;
import com.jh3502.vivo.view.treeview.BranchNode;
import com.jh3502.vivo.view.treeview.TreeNode;
import com.jh3502.vivo.view.treeview.TreeViewBinder;


public class BranchViewBinder extends TreeViewBinder<BranchViewBinder.ViewHolder> {
    boolean hidebutton;

    public BranchViewBinder(boolean b) {
        super();
        this.hidebutton = b;
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_branch;
    }

    @Override
    public int getToggleId() {
        return 0;
    }

    @Override
    public int getCheckedId() {
        return R.id.branch_check;
    }

    @Override
    public int getClickId() {
        return R.id.branch_parent;
    }


    @Override
    public ViewHolder creatViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    @Override
    public void bindViewHolder(ViewHolder holder, int position, TreeNode treeNode) {
        if (hidebutton) {
            (holder.findViewById(R.id.branch_check)).setVisibility(View.GONE);
        } else {
            (holder.findViewById(R.id.branch_check)).setVisibility(View.VISIBLE);
        }
        ((TextView) holder.findViewById(R.id.branch_name)).setText(((ContactBean) ((BranchNode) treeNode.getValue()).getBean()).getName());
        ((ImageView) holder.findViewById(R.id.branch_check)).setImageResource(
                treeNode.isChecked() ? R.drawable.btn_check_selected : R.drawable.plus_contact);
    }

    class ViewHolder extends TreeViewBinder.ViewHolder {
        public ViewHolder(View itemView) {
            super(itemView);
        }
    }
}
